home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / ENTRY.SWG / 0020_Re: Entering Characters.pas < prev    next >
Pascal/Delphi Source File  |  1995-02-28  |  3KB  |  94 lines

  1. {
  2.  SJ>     What is the best way to enter extended characters using readln?  I
  3.  SJ> would really like to assign Ctrl-E to ASCII 130.  I tried using ansi
  4.  SJ> and I could get it to work in dos but Pascal seems to override it.
  5.  SJ> Basically what I am tying to do is make it easy for the user to enter
  6.  SJ> foreign letters into a string.  Any suggestions would be appreciated.
  7.  SJ>                                             Stuart Johnston
  8.  
  9. To achieve this, you have to prog your own ReadLine-procedure, using
  10. the READKEY and KEYPRESSED functions of TP.
  11. You can't get READLN() to do the job for you. You have to do it your
  12. own. :-)
  13.  
  14. Here is an example of what an Input-Line routine could look like:
  15. It's only a small one. I also have a much more comfortable one, but it
  16. isn't finished yet. :-)))
  17.  
  18. ----------------------------------------------------------------------- }
  19.  
  20. uses CRT;
  21.  
  22. function InputLine(column, line, width, color : byte) : string;
  23. {
  24.  Function to read one line of input from the keyboard.
  25. }
  26.  
  27. var
  28.  
  29.  i     : byte;
  30.  key   : char;
  31.  coln  : byte;    { column of cursor position }
  32.  entry : byte;    { pointer into inputstring }
  33.  str   : string;  { input string }
  34.  
  35. begin
  36.  textattr := color;    { set color of whole line }
  37.  gotoxy(column, line);
  38.  for i := column to (column + width - 1) do
  39.   write(#32);
  40.  coln := column;
  41.  entry := 1;
  42.  str[0] := #0;  { empty string }
  43.  while (TRUE) do
  44.  begin
  45.   gotoxy(coln, line);
  46.   key := readkey;
  47.   case key of
  48.    #0 : begin  { Trace Function-keys }
  49.          key := readkey;
  50.         end;
  51.    #8 : begin  { BACKSPACE-key }
  52.          if (entry > 1) then
  53.          begin
  54.           coln := coln - 1;
  55.           gotoxy(coln, line);
  56.           write(#32);
  57.           entry := entry - 1;
  58.          end;
  59.         end;
  60.    #12 : begin        { Ctrl-L : delete entire line }
  61.           gotoxy(column, line);
  62.           for i := column to (column + width - 1) do
  63.            write(#32);
  64.           coln := column;
  65.           entry := 1;
  66.           str[0] := #0;  { empty string }
  67.          end;
  68.    #13 : begin  { RETURN-key }
  69.           if (entry > 1) then  { no RETURN with an empty line! }
  70.           begin
  71.            str[0] := char(entry - 1);  { set string length }
  72.            InputLine := str;
  73.            exit;
  74.           end;
  75.          end;
  76.    #27 : begin        { ESC-key : to abort the entry }
  77.           str := #255;            { set a marker for "ESC-key has been pressed" }
  78.           InputLine := str;
  79.           exit;
  80.          end;
  81.    #32..#254 : begin
  82.                 if (entry <= width) then { input field full? }
  83.                 begin
  84.                  write(key);
  85.                  str[entry] := key;
  86.                  entry := entry + 1;
  87.                  coln := coln + 1;
  88.                 end;
  89.                end;
  90.   end;
  91.  end;
  92. end;
  93.  
  94.